import { Request, Response, NextFunction } from "express";
import { connection } from "@/services/database";

export default async (_request: Request, response: Response, next: NextFunction) => {
	try {
		const callerId = response.locals.user.id;
		const [results] = (await connection.execute("SELECT user_id, username, phone_number, avatar, nickname FROM user WHERE user_id = :user_id", {
			user_id: callerId,
		})) as any;
		if (!results[0]) throw new Error("用户不存在");
		response.json({
			data: {
				user_id: results[0].user_id,
				username: results[0].username,
				phone_number: results[0].phone_number,
				avatar: results[0].avatar,
				nickname: results[0].nickname,
			},
			message: "成功",
		});
	} catch (error) {
		response.statusCode = 400;
		next(error);
	}
};
